#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int, int>
#define pil pair<int, ll>
#define pli pair<ll, int>
#define pll pair<ll, ll>

const ll mod = 1e9 + 7;
const int N = 2e5 + 5;

ll fac[N];

void solve(){
	int n, cnt = 0;
	cin >> n;
	vector<pii> pts(2 * n);
	vector<int> px(2 * n), py(2 * n);
	for(auto& [x, y] : pts){
		cin >> x >> y;
		px[cnt] = x, py[cnt++] = y;
	}

	sort(px.begin(), px.end());
	sort(py.begin(), py.end());

	int x1 = px[n - 1], x2 = px[n];
	int y1 = py[n - 1], y2 = py[n];

	if(x1 == x2){
		cout << 0 << '\n';
		return;
	}
	if(y1 == y2){
		cout << 0 << '\n';
		return;
	}

	ll a = 0, b = 0;
	for(int i = 0; i < 2 * n; i++){
		if(pts[i].first < x2){
			pts[i].second < y2 ? a++ : b++;
		}
	}

	ll res = 1LL * fac[a] * fac[b] % mod;

	cout << res << '\n';
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    fac[0] = 1;
    for(int i = 1; i <= 2e5; i++)fac[i] = 1LL * fac[i - 1] * i % mod;
    int t=1;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

// https://codeforces.com/gym/101968/problem/B

